﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using xIx.Web.AccessControl;
using System.Collections.Generic;

namespace MC
{
    public class QASubmitCtl : xIx.Web.Portal.SimpleFormBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected override bool CollectValues(Dictionary<string, object> vd)
        {
            if (Page.User == null || Page.User.AccountInfo == null) {
                Alert("请先登录，然后才能提交评论。");
                return false;
            }


            vd.Add("Title", GetIptText("QTitle"));
            vd.Add("QText", GetIptText("QText"));

            if (vd["Title"]==null||vd["Title"].ToString().Trim().Length<4 || vd["QText"]==null||vd["QText"].ToString().Trim().Length<4)
            {
                Alert("标题和内容都必须4个字以上。");
                return false;
            }

            vd.Add("QUserID", Page.User.AccountInfo.ID);
            vd.Add("QUserTitle", Page.User.AccountInfo.Name);
            vd.Add("QDate", DateTime.Now);
            vd.Add("IsReply", false);
            vd.Add("QUserDesc", GetIptText("QUserDesc"));
            vd.Add("QType", GetIptText("QType"));
            vd.Add("ExtA", UseUserImgSelCtl("ExtA"));
            //vd.Add("ExtB", GetIptText("ExtB"));
            //vd.Add("ExtC", GetIptText("ExtC"));
            //vd.Add("ExtD", GetIptText("ExtD"));
            //vd.Add("ExtE", GetIptText("ExtE"));
            return true;
        }

        protected override void OnAfterSave(Dictionary<string, object> vd, int r)
        {
            if (r == 1)
            {
                Alert("保存成功。");
            }
            else
            {
                Alert("保存失败。");
            }
        }
        public string UseUserImgSelCtl(string k)
        {
            UserImgSelectorCtlBase f = FindControlEx(k) as UserImgSelectorCtlBase;
            if (null == f) return null;

            f.SaveFile();
            return f.Text;
        }

        public override string TableName
        {
            get { return "Sys_QABoard"; }
        }

        public override string FieldsForDisplay
        {
            get { return "*"; }
        }
    }
}